package com.alm.token.ui.fragmentDialog;

import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.alm.token.R;
import com.alm.token.ui.data.bean.UserWalletData;

/**
 * 作者：
 * 时间： 2017/9/18
 * 描述：    测试1
 */

public class CreatNodeDialogFragment extends BaseDialogFragment {

    private TextView tvSure, tvCancle, tvContent, tvTitle;
    ClickListener clickListener;
    UserWalletData.DataBean.UserMsgBean userMsgBean;

    @Override
    protected int getLayoutId() {
        return R.layout.view_tosetpaypswdialog;
    }

    @Override
    protected void initView(Dialog dialog) {
        tvSure = (TextView) dialog.findViewById(R.id.tv_sure);
        tvSure.setText(getString(R.string.menu_hint_item3));
        tvCancle = (TextView) dialog.findViewById(R.id.tv_cancle);
        tvCancle.setText(getString(R.string.common_cancel));
        tvTitle = dialog.findViewById(R.id.tv_title);
        tvContent = dialog.findViewById(R.id.tv_content);

        userMsgBean = (UserWalletData.DataBean.UserMsgBean) getDialogBean().getT();

        tvTitle.setText(userMsgBean.getTitle());
        tvContent.setText(userMsgBean.getContent());

        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickListener != null) {
                    clickListener.Listener("", 2);
                }
                dismissParent();
            }
        });
        tvCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickListener != null) {
                    clickListener.Listener("", 1);
                }
                dismissParent();
            }
        });
    }


    @Override
    public int setThemeRes() {
        return R.style.BottomDialogFragment1;
    }

    private boolean outSidedismiss = true;

    @Override
    protected void setView() {
        dialog.setCanceledOnTouchOutside(outSidedismiss);
        final Window window = dialog.getWindow();
        final WindowManager.LayoutParams lp = window.getAttributes();
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.gravity = Gravity.CENTER;

        window.setAttributes(lp);
        if (!outSidedismiss) {
            getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    return keyCode == KeyEvent.KEYCODE_BACK;
                }
            });
        }
    }

    public void setListener(ClickListener clickListener) {
        this.clickListener = clickListener;
    }

    public interface ClickListener {
        void Listener(String name, int potion);
    }
}